// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
function useDebounceFn(fn: Function, time: number = 300) {
  let id: number|null = null;
  return function() {
    // eslint-disable-next-line prefer-rest-params
    const arr = arguments //包含传递给函数的每个参数
    if (id) {
      clearTimeout(id) //id有值，说明上次定时器还没执行完，这时清除上次定时器
    }
    id = setTimeout(() => {
      fn.call(this, ...arr) //arguments里的每个参数展开到send函数中作为实参
    }, time) as unknown as number;
  }
}
export default useDebounceFn;